<?php


namespace app\manage\controller;

use app\manage\model\Category as CategoryModel;


class Category extends Base
{
    public function index()
    {
        $categories = CategoryModel::with('child')->where('parent_id', '=', 0)->order('id', 'asc')->paginate(15);
        $this->assign('categories', $categories);
        return $this->fetch('category/index');
    }

    public function create()
    {
        if($this->request->isPost()){
            $data = $this->request->param();
            $category = new CategoryModel();
            $category->allowField(true)->isUpdate(false)->save($data);
            $this->redirect('category/index');
        }
        $categories = CategoryModel::getAll();
//        print_r($categories->toArray());die;
        $this->assign('categories', $categories);
        return $this->fetch('category/create');
    }

    public function detail($id)
    {

    }

    public function edit($id)
    {
        // TODO: Implement edit() method.
    }

    public function delete($id)
    {
        // TODO: Implement delete() method.
    }
}